function compose() {
  const funcs = [...arguments];
  return function (...args) {
    return funcs.reduce((prev, item) => {
      return item(prev);
    }, ...args);
  };
}

function add(a) {
  return a + 1;
}

function mul(a) {
  return a * 3;
}

function sub(a) {
  return a + 1000;
}

const addOne = compose(add);
const addOneOne = compose(add, mul);
const addOneOneOne = compose(add, mul, sub);
// addOneOne(2);
console.log(addOne(1));
console.log(addOneOne(1));
console.log(addOneOneOne(1));
